package com.count.core;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.p.Hands;

public class TotalCount {
	public static int preflopThreeBet;

	public static Map<String, Integer> rangeCountMap = new HashMap<String, Integer>();

	private static Map<String, PlayerCount> playerCountMap = new HashMap<String, PlayerCount>();

	public static PlayerCount getPlayerCount(String name) {
		if (playerCountMap.get(name) == null) {
			PlayerCount pc = new PlayerCount();
			playerCountMap.put(name, pc);
			return pc;
		}
		return playerCountMap.get(name);
	}

	private static void countPreflopAction(PlayerInfo pi) {
		if (pi.getPreflopBetTimes() == 2) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopOpenRaise(pc.getPreflopOpenRaise() + 1);
		} else if (pi.getPreflopBetTimes() == 3) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopThreebet(pc.getPreflopThreebet() + 1);
		} else if (pi.getPreflopBetTimes() == 4) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopFourbet(pc.getPreflopFourbet() + 1);
		} else if (pi.getPreflopBetTimes() == 5) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopFivebet(pc.getPreflopFivebet() + 1);
		} else if (pi.getPreflopBetTimes() == 6) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopSixbet(pc.getPreflopSixbet() + 1);
		}

		if (pi.getPreflopFold() == 2) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopOpenRaiseFold(pc.getPreflopOpenRaiseFold() + 1);
		} else if (pi.getPreflopFold() == 3) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopThreebetFold(pc.getPreflopThreebetFold() + 1);
		} else if (pi.getPreflopFold() == 4) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopFourbetFold(pc.getPreflopFourbetFold() + 1);
		} else if (pi.getPreflopFold() == 5) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopFivebetFold(pc.getPreflopFivebetFold() + 1);
		} else if (pi.getPreflopFold() == 6) {
			PlayerCount pc = TotalCount.getPlayerCount(pi.getName());
			pc.setPreflopSixbetFold(pc.getPreflopSixbetFold() + 1);
		}

		if (pi.getPreflopBetTimes() >= 3) {
			TotalCount.preflopThreeBet++;
		}
	}

	public static void count(List<G> gList) {
		for (G g : gList) {
			for (PlayerInfo pi : g.getPlayerInfoMap().values()) {
				countPreflopAction(pi);

				if (pi.getPreflopBetTimes()>=2 && pi.getHands().getP1() != null) {
					countRange(pi.getName(), pi.getHands());
				}
			}

		}
		
		for(String s:rangeCountMap.keySet()){
			System.out.println(s+" "+rangeCountMap.get(s));
		}

	}

	private static void countRange(String name, Hands hands) {
		PlayerCount pc = getPlayerCount(name);
		if (pc.getHandsCountMap().containsKey(hands.print())) {
			pc.getHandsCountMap().put(hands.print(), pc.getHandsCountMap().get(hands.print()).intValue() + 1);
		} else {
			pc.getHandsCountMap().put(hands.print(), 1);
		}

		if (rangeCountMap.containsKey(hands.print())) {
			rangeCountMap.put(hands.print(), rangeCountMap.get(hands.print()).intValue() + 1);
		} else {
			rangeCountMap.put(hands.print(), 1);
		}

	}
}
